package nina.yiyou.salary.input.util

import org.apache.poi.hssf.usermodel.HSSFWorkbook
import org.apache.poi.openxml4j.opc.OPCPackage
import org.apache.poi.openxml4j.opc.PackageAccess
import org.apache.poi.xssf.usermodel.XSSFWorkbook

import java.nio.file.Path

class ExcelReadOpener {

  static ExcelReadOpener get(Path path) {
    return new ExcelReadOpener(path.toString())
  }

  /**
   * @see #get
   */
  @Deprecated
  ExcelReadOpener(Path path) {
    this(path.toString())
  }

  ExcelReadOpener(String path) {
    _path = path
  }

  XSSFWorkbook openXlsx() {
    return new XSSFWorkbook(OPCPackage.open(_path, PackageAccess.READ))
  }

  HSSFWorkbook openXls() {
    return new HSSFWorkbook(new FileInputStream(_path))
  }

  private final String _path
}
